<?php
namespace Home\Controller;
use Think\Controller;

class LoginController extends Controller {

	public $Member = '';

	public function _initialize(){
		$this->Member = D('Member');
	}

	public function index(){
		if(empty($_POST)){
			$this->display();
		}else{
			$m_account = I('post.m_account');
			$m_password = md5(I('post.m_password'));
			$where = array('m_account'=>$m_account);
			$member = $this->Member->findMember($where);
			//dump($this->Member->_sql());die;
			$data['last_login_time'] = time();
			$this->Member->editMember($where,$data);
			if(!$member || $member['m_password'] != $m_password){
				$this->error('用户名或密码错误！');
			}else{
				session('M_ID',$member['m_id']);
				session('M_TYPE',$member['m_type']);
				session('M_ACCOUNT',$member['m_account']);
				session('M_NICKNAME',$member['m_nickname']);
				header('Content-type:text/html;Charset=UTF-8');
            	redirect(__APP__); 
			}
		}
	}


	//退出登录
	public function loginOut(){
		session('M_ID',null);
		session('M_ACCOUNT',null);
		session('M_NICKNAME',null);
		redirect(U('Login/index'));
	}

}


?>